/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package vn.com.fis.portal.service.persistence;

import com.liferay.portal.NoSuchModelException;
import com.liferay.portal.kernel.bean.BeanReference;
import com.liferay.portal.kernel.cache.CacheRegistryUtil;
import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
import com.liferay.portal.kernel.dao.jdbc.RowMapper;
import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderPath;
import com.liferay.portal.kernel.dao.orm.Query;
import com.liferay.portal.kernel.dao.orm.QueryPos;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.dao.orm.SQLQuery;
import com.liferay.portal.kernel.dao.orm.Session;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.InstanceFactory;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.kernel.util.PropsKeys;
import com.liferay.portal.kernel.util.PropsUtil;
import com.liferay.portal.kernel.util.SetUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.ModelListener;
import com.liferay.portal.service.persistence.BatchSessionUtil;
import com.liferay.portal.service.persistence.ResourcePersistence;
import com.liferay.portal.service.persistence.UserPersistence;
import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;

import vn.com.fis.portal.NoSuchVideoEntryException;
import vn.com.fis.portal.model.VideoEntry;
import vn.com.fis.portal.model.impl.VideoEntryImpl;
import vn.com.fis.portal.model.impl.VideoEntryModelImpl;

import java.io.Serializable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;

/**
 * The persistence implementation for the video entry service.
 *
 * <p>
 * Caching information and settings can be found in <code>portal.properties</code>
 * </p>
 *
 * @author loind
 * @see VideoEntryPersistence
 * @see VideoEntryUtil
 * @generated
 */
public class VideoEntryPersistenceImpl extends BasePersistenceImpl<VideoEntry>
	implements VideoEntryPersistence {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. Always use {@link VideoEntryUtil} to access the video entry persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
	 */
	public static final String FINDER_CLASS_NAME_ENTITY = VideoEntryImpl.class.getName();
	public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
		".List1";
	public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
		".List2";
	public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_NAME_UPLOADERID_FOLDERID =
		new FinderPath(VideoEntryModelImpl.ENTITY_CACHE_ENABLED,
			VideoEntryModelImpl.FINDER_CACHE_ENABLED, VideoEntryImpl.class,
			FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
			"findByName_UploaderId_FolderId",
			new String[] {
				String.class.getName(), Long.class.getName(),
				Long.class.getName(),
				
			"java.lang.Integer", "java.lang.Integer",
				"com.liferay.portal.kernel.util.OrderByComparator"
			});
	public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME_UPLOADERID_FOLDERID =
		new FinderPath(VideoEntryModelImpl.ENTITY_CACHE_ENABLED,
			VideoEntryModelImpl.FINDER_CACHE_ENABLED, VideoEntryImpl.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"findByName_UploaderId_FolderId",
			new String[] {
				String.class.getName(), Long.class.getName(),
				Long.class.getName()
			},
			VideoEntryModelImpl.VIDEONAME_COLUMN_BITMASK |
			VideoEntryModelImpl.UPLOADERID_COLUMN_BITMASK |
			VideoEntryModelImpl.FOLDERID_COLUMN_BITMASK);
	public static final FinderPath FINDER_PATH_COUNT_BY_NAME_UPLOADERID_FOLDERID =
		new FinderPath(VideoEntryModelImpl.ENTITY_CACHE_ENABLED,
			VideoEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"countByName_UploaderId_FolderId",
			new String[] {
				String.class.getName(), Long.class.getName(),
				Long.class.getName()
			});
	public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_NAME_UPLOADERID =
		new FinderPath(VideoEntryModelImpl.ENTITY_CACHE_ENABLED,
			VideoEntryModelImpl.FINDER_CACHE_ENABLED, VideoEntryImpl.class,
			FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByName_UploaderId",
			new String[] {
				String.class.getName(), Long.class.getName(),
				
			"java.lang.Integer", "java.lang.Integer",
				"com.liferay.portal.kernel.util.OrderByComparator"
			});
	public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME_UPLOADERID =
		new FinderPath(VideoEntryModelImpl.ENTITY_CACHE_ENABLED,
			VideoEntryModelImpl.FINDER_CACHE_ENABLED, VideoEntryImpl.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByName_UploaderId",
			new String[] { String.class.getName(), Long.class.getName() },
			VideoEntryModelImpl.VIDEONAME_COLUMN_BITMASK |
			VideoEntryModelImpl.UPLOADERID_COLUMN_BITMASK);
	public static final FinderPath FINDER_PATH_COUNT_BY_NAME_UPLOADERID = new FinderPath(VideoEntryModelImpl.ENTITY_CACHE_ENABLED,
			VideoEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"countByName_UploaderId",
			new String[] { String.class.getName(), Long.class.getName() });
	public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(VideoEntryModelImpl.ENTITY_CACHE_ENABLED,
			VideoEntryModelImpl.FINDER_CACHE_ENABLED, VideoEntryImpl.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
	public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(VideoEntryModelImpl.ENTITY_CACHE_ENABLED,
			VideoEntryModelImpl.FINDER_CACHE_ENABLED, VideoEntryImpl.class,
			FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
	public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(VideoEntryModelImpl.ENTITY_CACHE_ENABLED,
			VideoEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);

	/**
	 * Caches the video entry in the entity cache if it is enabled.
	 *
	 * @param videoEntry the video entry
	 */
	public void cacheResult(VideoEntry videoEntry) {
		EntityCacheUtil.putResult(VideoEntryModelImpl.ENTITY_CACHE_ENABLED,
			VideoEntryImpl.class, videoEntry.getPrimaryKey(), videoEntry);

		videoEntry.resetOriginalValues();
	}

	/**
	 * Caches the video entries in the entity cache if it is enabled.
	 *
	 * @param videoEntries the video entries
	 */
	public void cacheResult(List<VideoEntry> videoEntries) {
		for (VideoEntry videoEntry : videoEntries) {
			if (EntityCacheUtil.getResult(
						VideoEntryModelImpl.ENTITY_CACHE_ENABLED,
						VideoEntryImpl.class, videoEntry.getPrimaryKey()) == null) {
				cacheResult(videoEntry);
			}
			else {
				videoEntry.resetOriginalValues();
			}
		}
	}

	/**
	 * Clears the cache for all video entries.
	 *
	 * <p>
	 * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
	 * </p>
	 */
	@Override
	public void clearCache() {
		if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
			CacheRegistryUtil.clear(VideoEntryImpl.class.getName());
		}

		EntityCacheUtil.clearCache(VideoEntryImpl.class.getName());

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
	}

	/**
	 * Clears the cache for the video entry.
	 *
	 * <p>
	 * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
	 * </p>
	 */
	@Override
	public void clearCache(VideoEntry videoEntry) {
		EntityCacheUtil.removeResult(VideoEntryModelImpl.ENTITY_CACHE_ENABLED,
			VideoEntryImpl.class, videoEntry.getPrimaryKey());

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
	}

	@Override
	public void clearCache(List<VideoEntry> videoEntries) {
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);

		for (VideoEntry videoEntry : videoEntries) {
			EntityCacheUtil.removeResult(VideoEntryModelImpl.ENTITY_CACHE_ENABLED,
				VideoEntryImpl.class, videoEntry.getPrimaryKey());
		}
	}

	/**
	 * Creates a new video entry with the primary key. Does not add the video entry to the database.
	 *
	 * @param videoId the primary key for the new video entry
	 * @return the new video entry
	 */
	public VideoEntry create(long videoId) {
		VideoEntry videoEntry = new VideoEntryImpl();

		videoEntry.setNew(true);
		videoEntry.setPrimaryKey(videoId);

		return videoEntry;
	}

	/**
	 * Removes the video entry with the primary key from the database. Also notifies the appropriate model listeners.
	 *
	 * @param videoId the primary key of the video entry
	 * @return the video entry that was removed
	 * @throws vn.com.fis.portal.NoSuchVideoEntryException if a video entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public VideoEntry remove(long videoId)
		throws NoSuchVideoEntryException, SystemException {
		return remove(Long.valueOf(videoId));
	}

	/**
	 * Removes the video entry with the primary key from the database. Also notifies the appropriate model listeners.
	 *
	 * @param primaryKey the primary key of the video entry
	 * @return the video entry that was removed
	 * @throws vn.com.fis.portal.NoSuchVideoEntryException if a video entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public VideoEntry remove(Serializable primaryKey)
		throws NoSuchVideoEntryException, SystemException {
		Session session = null;

		try {
			session = openSession();

			VideoEntry videoEntry = (VideoEntry)session.get(VideoEntryImpl.class,
					primaryKey);

			if (videoEntry == null) {
				if (_log.isWarnEnabled()) {
					_log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
				}

				throw new NoSuchVideoEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
					primaryKey);
			}

			return remove(videoEntry);
		}
		catch (NoSuchVideoEntryException nsee) {
			throw nsee;
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}
	}

	@Override
	protected VideoEntry removeImpl(VideoEntry videoEntry)
		throws SystemException {
		videoEntry = toUnwrappedModel(videoEntry);

		try {
			clearUserEntries.clear(videoEntry.getPrimaryKey());
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(VideoEntryModelImpl.MAPPING_TABLE_TBL_VIDEO_USER_NAME);
		}

		try {
			clearCategoryEntries.clear(videoEntry.getPrimaryKey());
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(VideoEntryModelImpl.MAPPING_TABLE_TBL_CATEGORY_VIDEO_NAME);
		}

		Session session = null;

		try {
			session = openSession();

			BatchSessionUtil.delete(session, videoEntry);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}

		clearCache(videoEntry);

		return videoEntry;
	}

	@Override
	public VideoEntry updateImpl(
		vn.com.fis.portal.model.VideoEntry videoEntry, boolean merge)
		throws SystemException {
		videoEntry = toUnwrappedModel(videoEntry);

		boolean isNew = videoEntry.isNew();

		VideoEntryModelImpl videoEntryModelImpl = (VideoEntryModelImpl)videoEntry;

		Session session = null;

		try {
			session = openSession();

			BatchSessionUtil.update(session, videoEntry, merge);

			videoEntry.setNew(false);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);

		if (isNew || !VideoEntryModelImpl.COLUMN_BITMASK_ENABLED) {
			FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
		}

		else {
			if ((videoEntryModelImpl.getColumnBitmask() &
					FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME_UPLOADERID_FOLDERID.getColumnBitmask()) != 0) {
				Object[] args = new Object[] {
						videoEntryModelImpl.getOriginalVideoName(),
						Long.valueOf(videoEntryModelImpl.getOriginalUploaderId()),
						Long.valueOf(videoEntryModelImpl.getOriginalFolderId())
					};

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME_UPLOADERID_FOLDERID,
					args);
				FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME_UPLOADERID_FOLDERID,
					args);

				args = new Object[] {
						videoEntryModelImpl.getVideoName(),
						Long.valueOf(videoEntryModelImpl.getUploaderId()),
						Long.valueOf(videoEntryModelImpl.getFolderId())
					};

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME_UPLOADERID_FOLDERID,
					args);
				FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME_UPLOADERID_FOLDERID,
					args);
			}

			if ((videoEntryModelImpl.getColumnBitmask() &
					FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME_UPLOADERID.getColumnBitmask()) != 0) {
				Object[] args = new Object[] {
						videoEntryModelImpl.getOriginalVideoName(),
						Long.valueOf(videoEntryModelImpl.getOriginalUploaderId())
					};

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME_UPLOADERID,
					args);
				FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME_UPLOADERID,
					args);

				args = new Object[] {
						videoEntryModelImpl.getVideoName(),
						Long.valueOf(videoEntryModelImpl.getUploaderId())
					};

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME_UPLOADERID,
					args);
				FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME_UPLOADERID,
					args);
			}
		}

		EntityCacheUtil.putResult(VideoEntryModelImpl.ENTITY_CACHE_ENABLED,
			VideoEntryImpl.class, videoEntry.getPrimaryKey(), videoEntry);

		return videoEntry;
	}

	protected VideoEntry toUnwrappedModel(VideoEntry videoEntry) {
		if (videoEntry instanceof VideoEntryImpl) {
			return videoEntry;
		}

		VideoEntryImpl videoEntryImpl = new VideoEntryImpl();

		videoEntryImpl.setNew(videoEntry.isNew());
		videoEntryImpl.setPrimaryKey(videoEntry.getPrimaryKey());

		videoEntryImpl.setVideoId(videoEntry.getVideoId());
		videoEntryImpl.setVideoName(videoEntry.getVideoName());
		videoEntryImpl.setVideoUrl(videoEntry.getVideoUrl());
		videoEntryImpl.setFolderId(videoEntry.getFolderId());
		videoEntryImpl.setSize(videoEntry.getSize());
		videoEntryImpl.setFormat(videoEntry.getFormat());
		videoEntryImpl.setDescription(videoEntry.getDescription());
		videoEntryImpl.setAccessModifier(videoEntry.getAccessModifier());
		videoEntryImpl.setSmallImageUrl(videoEntry.getSmallImageUrl());
		videoEntryImpl.setLargeImageUrl(videoEntry.getLargeImageUrl());
		videoEntryImpl.setStatus(videoEntry.getStatus());
		videoEntryImpl.setUploaderId(videoEntry.getUploaderId());

		return videoEntryImpl;
	}

	/**
	 * Returns the video entry with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
	 *
	 * @param primaryKey the primary key of the video entry
	 * @return the video entry
	 * @throws com.liferay.portal.NoSuchModelException if a video entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public VideoEntry findByPrimaryKey(Serializable primaryKey)
		throws NoSuchModelException, SystemException {
		return findByPrimaryKey(((Long)primaryKey).longValue());
	}

	/**
	 * Returns the video entry with the primary key or throws a {@link vn.com.fis.portal.NoSuchVideoEntryException} if it could not be found.
	 *
	 * @param videoId the primary key of the video entry
	 * @return the video entry
	 * @throws vn.com.fis.portal.NoSuchVideoEntryException if a video entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public VideoEntry findByPrimaryKey(long videoId)
		throws NoSuchVideoEntryException, SystemException {
		VideoEntry videoEntry = fetchByPrimaryKey(videoId);

		if (videoEntry == null) {
			if (_log.isWarnEnabled()) {
				_log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + videoId);
			}

			throw new NoSuchVideoEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
				videoId);
		}

		return videoEntry;
	}

	/**
	 * Returns the video entry with the primary key or returns <code>null</code> if it could not be found.
	 *
	 * @param primaryKey the primary key of the video entry
	 * @return the video entry, or <code>null</code> if a video entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public VideoEntry fetchByPrimaryKey(Serializable primaryKey)
		throws SystemException {
		return fetchByPrimaryKey(((Long)primaryKey).longValue());
	}

	/**
	 * Returns the video entry with the primary key or returns <code>null</code> if it could not be found.
	 *
	 * @param videoId the primary key of the video entry
	 * @return the video entry, or <code>null</code> if a video entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public VideoEntry fetchByPrimaryKey(long videoId) throws SystemException {
		VideoEntry videoEntry = (VideoEntry)EntityCacheUtil.getResult(VideoEntryModelImpl.ENTITY_CACHE_ENABLED,
				VideoEntryImpl.class, videoId);

		if (videoEntry == _nullVideoEntry) {
			return null;
		}

		if (videoEntry == null) {
			Session session = null;

			boolean hasException = false;

			try {
				session = openSession();

				videoEntry = (VideoEntry)session.get(VideoEntryImpl.class,
						Long.valueOf(videoId));
			}
			catch (Exception e) {
				hasException = true;

				throw processException(e);
			}
			finally {
				if (videoEntry != null) {
					cacheResult(videoEntry);
				}
				else if (!hasException) {
					EntityCacheUtil.putResult(VideoEntryModelImpl.ENTITY_CACHE_ENABLED,
						VideoEntryImpl.class, videoId, _nullVideoEntry);
				}

				closeSession(session);
			}
		}

		return videoEntry;
	}

	/**
	 * Returns all the video entries where videoName = &#63; and uploaderId = &#63; and folderId = &#63;.
	 *
	 * @param videoName the video name
	 * @param uploaderId the uploader ID
	 * @param folderId the folder ID
	 * @return the matching video entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<VideoEntry> findByName_UploaderId_FolderId(String videoName,
		long uploaderId, long folderId) throws SystemException {
		return findByName_UploaderId_FolderId(videoName, uploaderId, folderId,
			QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
	}

	/**
	 * Returns a range of all the video entries where videoName = &#63; and uploaderId = &#63; and folderId = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param videoName the video name
	 * @param uploaderId the uploader ID
	 * @param folderId the folder ID
	 * @param start the lower bound of the range of video entries
	 * @param end the upper bound of the range of video entries (not inclusive)
	 * @return the range of matching video entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<VideoEntry> findByName_UploaderId_FolderId(String videoName,
		long uploaderId, long folderId, int start, int end)
		throws SystemException {
		return findByName_UploaderId_FolderId(videoName, uploaderId, folderId,
			start, end, null);
	}

	/**
	 * Returns an ordered range of all the video entries where videoName = &#63; and uploaderId = &#63; and folderId = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param videoName the video name
	 * @param uploaderId the uploader ID
	 * @param folderId the folder ID
	 * @param start the lower bound of the range of video entries
	 * @param end the upper bound of the range of video entries (not inclusive)
	 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
	 * @return the ordered range of matching video entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<VideoEntry> findByName_UploaderId_FolderId(String videoName,
		long uploaderId, long folderId, int start, int end,
		OrderByComparator orderByComparator) throws SystemException {
		FinderPath finderPath = null;
		Object[] finderArgs = null;

		if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
				(orderByComparator == null)) {
			finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME_UPLOADERID_FOLDERID;
			finderArgs = new Object[] { videoName, uploaderId, folderId };
		}
		else {
			finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_NAME_UPLOADERID_FOLDERID;
			finderArgs = new Object[] {
					videoName, uploaderId, folderId,
					
					start, end, orderByComparator
				};
		}

		List<VideoEntry> list = (List<VideoEntry>)FinderCacheUtil.getResult(finderPath,
				finderArgs, this);

		if (list == null) {
			StringBundler query = null;

			if (orderByComparator != null) {
				query = new StringBundler(5 +
						(orderByComparator.getOrderByFields().length * 3));
			}
			else {
				query = new StringBundler(5);
			}

			query.append(_SQL_SELECT_VIDEOENTRY_WHERE);

			if (videoName == null) {
				query.append(_FINDER_COLUMN_NAME_UPLOADERID_FOLDERID_VIDEONAME_1);
			}
			else {
				if (videoName.equals(StringPool.BLANK)) {
					query.append(_FINDER_COLUMN_NAME_UPLOADERID_FOLDERID_VIDEONAME_3);
				}
				else {
					query.append(_FINDER_COLUMN_NAME_UPLOADERID_FOLDERID_VIDEONAME_2);
				}
			}

			query.append(_FINDER_COLUMN_NAME_UPLOADERID_FOLDERID_UPLOADERID_2);

			query.append(_FINDER_COLUMN_NAME_UPLOADERID_FOLDERID_FOLDERID_2);

			if (orderByComparator != null) {
				appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
					orderByComparator);
			}

			else {
				query.append(VideoEntryModelImpl.ORDER_BY_JPQL);
			}

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				if (videoName != null) {
					qPos.add(videoName);
				}

				qPos.add(uploaderId);

				qPos.add(folderId);

				list = (List<VideoEntry>)QueryUtil.list(q, getDialect(), start,
						end);
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(finderPath, finderArgs);
				}
				else {
					cacheResult(list);

					FinderCacheUtil.putResult(finderPath, finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	/**
	 * Returns the first video entry in the ordered set where videoName = &#63; and uploaderId = &#63; and folderId = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param videoName the video name
	 * @param uploaderId the uploader ID
	 * @param folderId the folder ID
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the first matching video entry
	 * @throws vn.com.fis.portal.NoSuchVideoEntryException if a matching video entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public VideoEntry findByName_UploaderId_FolderId_First(String videoName,
		long uploaderId, long folderId, OrderByComparator orderByComparator)
		throws NoSuchVideoEntryException, SystemException {
		List<VideoEntry> list = findByName_UploaderId_FolderId(videoName,
				uploaderId, folderId, 0, 1, orderByComparator);

		if (list.isEmpty()) {
			StringBundler msg = new StringBundler(8);

			msg.append(_NO_SUCH_ENTITY_WITH_KEY);

			msg.append("videoName=");
			msg.append(videoName);

			msg.append(", uploaderId=");
			msg.append(uploaderId);

			msg.append(", folderId=");
			msg.append(folderId);

			msg.append(StringPool.CLOSE_CURLY_BRACE);

			throw new NoSuchVideoEntryException(msg.toString());
		}
		else {
			return list.get(0);
		}
	}

	/**
	 * Returns the last video entry in the ordered set where videoName = &#63; and uploaderId = &#63; and folderId = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param videoName the video name
	 * @param uploaderId the uploader ID
	 * @param folderId the folder ID
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the last matching video entry
	 * @throws vn.com.fis.portal.NoSuchVideoEntryException if a matching video entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public VideoEntry findByName_UploaderId_FolderId_Last(String videoName,
		long uploaderId, long folderId, OrderByComparator orderByComparator)
		throws NoSuchVideoEntryException, SystemException {
		int count = countByName_UploaderId_FolderId(videoName, uploaderId,
				folderId);

		List<VideoEntry> list = findByName_UploaderId_FolderId(videoName,
				uploaderId, folderId, count - 1, count, orderByComparator);

		if (list.isEmpty()) {
			StringBundler msg = new StringBundler(8);

			msg.append(_NO_SUCH_ENTITY_WITH_KEY);

			msg.append("videoName=");
			msg.append(videoName);

			msg.append(", uploaderId=");
			msg.append(uploaderId);

			msg.append(", folderId=");
			msg.append(folderId);

			msg.append(StringPool.CLOSE_CURLY_BRACE);

			throw new NoSuchVideoEntryException(msg.toString());
		}
		else {
			return list.get(0);
		}
	}

	/**
	 * Returns the video entries before and after the current video entry in the ordered set where videoName = &#63; and uploaderId = &#63; and folderId = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param videoId the primary key of the current video entry
	 * @param videoName the video name
	 * @param uploaderId the uploader ID
	 * @param folderId the folder ID
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the previous, current, and next video entry
	 * @throws vn.com.fis.portal.NoSuchVideoEntryException if a video entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public VideoEntry[] findByName_UploaderId_FolderId_PrevAndNext(
		long videoId, String videoName, long uploaderId, long folderId,
		OrderByComparator orderByComparator)
		throws NoSuchVideoEntryException, SystemException {
		VideoEntry videoEntry = findByPrimaryKey(videoId);

		Session session = null;

		try {
			session = openSession();

			VideoEntry[] array = new VideoEntryImpl[3];

			array[0] = getByName_UploaderId_FolderId_PrevAndNext(session,
					videoEntry, videoName, uploaderId, folderId,
					orderByComparator, true);

			array[1] = videoEntry;

			array[2] = getByName_UploaderId_FolderId_PrevAndNext(session,
					videoEntry, videoName, uploaderId, folderId,
					orderByComparator, false);

			return array;
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}
	}

	protected VideoEntry getByName_UploaderId_FolderId_PrevAndNext(
		Session session, VideoEntry videoEntry, String videoName,
		long uploaderId, long folderId, OrderByComparator orderByComparator,
		boolean previous) {
		StringBundler query = null;

		if (orderByComparator != null) {
			query = new StringBundler(6 +
					(orderByComparator.getOrderByFields().length * 6));
		}
		else {
			query = new StringBundler(3);
		}

		query.append(_SQL_SELECT_VIDEOENTRY_WHERE);

		if (videoName == null) {
			query.append(_FINDER_COLUMN_NAME_UPLOADERID_FOLDERID_VIDEONAME_1);
		}
		else {
			if (videoName.equals(StringPool.BLANK)) {
				query.append(_FINDER_COLUMN_NAME_UPLOADERID_FOLDERID_VIDEONAME_3);
			}
			else {
				query.append(_FINDER_COLUMN_NAME_UPLOADERID_FOLDERID_VIDEONAME_2);
			}
		}

		query.append(_FINDER_COLUMN_NAME_UPLOADERID_FOLDERID_UPLOADERID_2);

		query.append(_FINDER_COLUMN_NAME_UPLOADERID_FOLDERID_FOLDERID_2);

		if (orderByComparator != null) {
			String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();

			if (orderByConditionFields.length > 0) {
				query.append(WHERE_AND);
			}

			for (int i = 0; i < orderByConditionFields.length; i++) {
				query.append(_ORDER_BY_ENTITY_ALIAS);
				query.append(orderByConditionFields[i]);

				if ((i + 1) < orderByConditionFields.length) {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(WHERE_GREATER_THAN_HAS_NEXT);
					}
					else {
						query.append(WHERE_LESSER_THAN_HAS_NEXT);
					}
				}
				else {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(WHERE_GREATER_THAN);
					}
					else {
						query.append(WHERE_LESSER_THAN);
					}
				}
			}

			query.append(ORDER_BY_CLAUSE);

			String[] orderByFields = orderByComparator.getOrderByFields();

			for (int i = 0; i < orderByFields.length; i++) {
				query.append(_ORDER_BY_ENTITY_ALIAS);
				query.append(orderByFields[i]);

				if ((i + 1) < orderByFields.length) {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(ORDER_BY_ASC_HAS_NEXT);
					}
					else {
						query.append(ORDER_BY_DESC_HAS_NEXT);
					}
				}
				else {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(ORDER_BY_ASC);
					}
					else {
						query.append(ORDER_BY_DESC);
					}
				}
			}
		}

		else {
			query.append(VideoEntryModelImpl.ORDER_BY_JPQL);
		}

		String sql = query.toString();

		Query q = session.createQuery(sql);

		q.setFirstResult(0);
		q.setMaxResults(2);

		QueryPos qPos = QueryPos.getInstance(q);

		if (videoName != null) {
			qPos.add(videoName);
		}

		qPos.add(uploaderId);

		qPos.add(folderId);

		if (orderByComparator != null) {
			Object[] values = orderByComparator.getOrderByConditionValues(videoEntry);

			for (Object value : values) {
				qPos.add(value);
			}
		}

		List<VideoEntry> list = q.list();

		if (list.size() == 2) {
			return list.get(1);
		}
		else {
			return null;
		}
	}

	/**
	 * Returns all the video entries where videoName = &#63; and uploaderId = &#63;.
	 *
	 * @param videoName the video name
	 * @param uploaderId the uploader ID
	 * @return the matching video entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<VideoEntry> findByName_UploaderId(String videoName,
		long uploaderId) throws SystemException {
		return findByName_UploaderId(videoName, uploaderId, QueryUtil.ALL_POS,
			QueryUtil.ALL_POS, null);
	}

	/**
	 * Returns a range of all the video entries where videoName = &#63; and uploaderId = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param videoName the video name
	 * @param uploaderId the uploader ID
	 * @param start the lower bound of the range of video entries
	 * @param end the upper bound of the range of video entries (not inclusive)
	 * @return the range of matching video entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<VideoEntry> findByName_UploaderId(String videoName,
		long uploaderId, int start, int end) throws SystemException {
		return findByName_UploaderId(videoName, uploaderId, start, end, null);
	}

	/**
	 * Returns an ordered range of all the video entries where videoName = &#63; and uploaderId = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param videoName the video name
	 * @param uploaderId the uploader ID
	 * @param start the lower bound of the range of video entries
	 * @param end the upper bound of the range of video entries (not inclusive)
	 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
	 * @return the ordered range of matching video entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<VideoEntry> findByName_UploaderId(String videoName,
		long uploaderId, int start, int end, OrderByComparator orderByComparator)
		throws SystemException {
		FinderPath finderPath = null;
		Object[] finderArgs = null;

		if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
				(orderByComparator == null)) {
			finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME_UPLOADERID;
			finderArgs = new Object[] { videoName, uploaderId };
		}
		else {
			finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_NAME_UPLOADERID;
			finderArgs = new Object[] {
					videoName, uploaderId,
					
					start, end, orderByComparator
				};
		}

		List<VideoEntry> list = (List<VideoEntry>)FinderCacheUtil.getResult(finderPath,
				finderArgs, this);

		if (list == null) {
			StringBundler query = null;

			if (orderByComparator != null) {
				query = new StringBundler(4 +
						(orderByComparator.getOrderByFields().length * 3));
			}
			else {
				query = new StringBundler(4);
			}

			query.append(_SQL_SELECT_VIDEOENTRY_WHERE);

			if (videoName == null) {
				query.append(_FINDER_COLUMN_NAME_UPLOADERID_VIDEONAME_1);
			}
			else {
				if (videoName.equals(StringPool.BLANK)) {
					query.append(_FINDER_COLUMN_NAME_UPLOADERID_VIDEONAME_3);
				}
				else {
					query.append(_FINDER_COLUMN_NAME_UPLOADERID_VIDEONAME_2);
				}
			}

			query.append(_FINDER_COLUMN_NAME_UPLOADERID_UPLOADERID_2);

			if (orderByComparator != null) {
				appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
					orderByComparator);
			}

			else {
				query.append(VideoEntryModelImpl.ORDER_BY_JPQL);
			}

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				if (videoName != null) {
					qPos.add(videoName);
				}

				qPos.add(uploaderId);

				list = (List<VideoEntry>)QueryUtil.list(q, getDialect(), start,
						end);
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(finderPath, finderArgs);
				}
				else {
					cacheResult(list);

					FinderCacheUtil.putResult(finderPath, finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	/**
	 * Returns the first video entry in the ordered set where videoName = &#63; and uploaderId = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param videoName the video name
	 * @param uploaderId the uploader ID
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the first matching video entry
	 * @throws vn.com.fis.portal.NoSuchVideoEntryException if a matching video entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public VideoEntry findByName_UploaderId_First(String videoName,
		long uploaderId, OrderByComparator orderByComparator)
		throws NoSuchVideoEntryException, SystemException {
		List<VideoEntry> list = findByName_UploaderId(videoName, uploaderId, 0,
				1, orderByComparator);

		if (list.isEmpty()) {
			StringBundler msg = new StringBundler(6);

			msg.append(_NO_SUCH_ENTITY_WITH_KEY);

			msg.append("videoName=");
			msg.append(videoName);

			msg.append(", uploaderId=");
			msg.append(uploaderId);

			msg.append(StringPool.CLOSE_CURLY_BRACE);

			throw new NoSuchVideoEntryException(msg.toString());
		}
		else {
			return list.get(0);
		}
	}

	/**
	 * Returns the last video entry in the ordered set where videoName = &#63; and uploaderId = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param videoName the video name
	 * @param uploaderId the uploader ID
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the last matching video entry
	 * @throws vn.com.fis.portal.NoSuchVideoEntryException if a matching video entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public VideoEntry findByName_UploaderId_Last(String videoName,
		long uploaderId, OrderByComparator orderByComparator)
		throws NoSuchVideoEntryException, SystemException {
		int count = countByName_UploaderId(videoName, uploaderId);

		List<VideoEntry> list = findByName_UploaderId(videoName, uploaderId,
				count - 1, count, orderByComparator);

		if (list.isEmpty()) {
			StringBundler msg = new StringBundler(6);

			msg.append(_NO_SUCH_ENTITY_WITH_KEY);

			msg.append("videoName=");
			msg.append(videoName);

			msg.append(", uploaderId=");
			msg.append(uploaderId);

			msg.append(StringPool.CLOSE_CURLY_BRACE);

			throw new NoSuchVideoEntryException(msg.toString());
		}
		else {
			return list.get(0);
		}
	}

	/**
	 * Returns the video entries before and after the current video entry in the ordered set where videoName = &#63; and uploaderId = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param videoId the primary key of the current video entry
	 * @param videoName the video name
	 * @param uploaderId the uploader ID
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the previous, current, and next video entry
	 * @throws vn.com.fis.portal.NoSuchVideoEntryException if a video entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public VideoEntry[] findByName_UploaderId_PrevAndNext(long videoId,
		String videoName, long uploaderId, OrderByComparator orderByComparator)
		throws NoSuchVideoEntryException, SystemException {
		VideoEntry videoEntry = findByPrimaryKey(videoId);

		Session session = null;

		try {
			session = openSession();

			VideoEntry[] array = new VideoEntryImpl[3];

			array[0] = getByName_UploaderId_PrevAndNext(session, videoEntry,
					videoName, uploaderId, orderByComparator, true);

			array[1] = videoEntry;

			array[2] = getByName_UploaderId_PrevAndNext(session, videoEntry,
					videoName, uploaderId, orderByComparator, false);

			return array;
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}
	}

	protected VideoEntry getByName_UploaderId_PrevAndNext(Session session,
		VideoEntry videoEntry, String videoName, long uploaderId,
		OrderByComparator orderByComparator, boolean previous) {
		StringBundler query = null;

		if (orderByComparator != null) {
			query = new StringBundler(6 +
					(orderByComparator.getOrderByFields().length * 6));
		}
		else {
			query = new StringBundler(3);
		}

		query.append(_SQL_SELECT_VIDEOENTRY_WHERE);

		if (videoName == null) {
			query.append(_FINDER_COLUMN_NAME_UPLOADERID_VIDEONAME_1);
		}
		else {
			if (videoName.equals(StringPool.BLANK)) {
				query.append(_FINDER_COLUMN_NAME_UPLOADERID_VIDEONAME_3);
			}
			else {
				query.append(_FINDER_COLUMN_NAME_UPLOADERID_VIDEONAME_2);
			}
		}

		query.append(_FINDER_COLUMN_NAME_UPLOADERID_UPLOADERID_2);

		if (orderByComparator != null) {
			String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();

			if (orderByConditionFields.length > 0) {
				query.append(WHERE_AND);
			}

			for (int i = 0; i < orderByConditionFields.length; i++) {
				query.append(_ORDER_BY_ENTITY_ALIAS);
				query.append(orderByConditionFields[i]);

				if ((i + 1) < orderByConditionFields.length) {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(WHERE_GREATER_THAN_HAS_NEXT);
					}
					else {
						query.append(WHERE_LESSER_THAN_HAS_NEXT);
					}
				}
				else {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(WHERE_GREATER_THAN);
					}
					else {
						query.append(WHERE_LESSER_THAN);
					}
				}
			}

			query.append(ORDER_BY_CLAUSE);

			String[] orderByFields = orderByComparator.getOrderByFields();

			for (int i = 0; i < orderByFields.length; i++) {
				query.append(_ORDER_BY_ENTITY_ALIAS);
				query.append(orderByFields[i]);

				if ((i + 1) < orderByFields.length) {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(ORDER_BY_ASC_HAS_NEXT);
					}
					else {
						query.append(ORDER_BY_DESC_HAS_NEXT);
					}
				}
				else {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(ORDER_BY_ASC);
					}
					else {
						query.append(ORDER_BY_DESC);
					}
				}
			}
		}

		else {
			query.append(VideoEntryModelImpl.ORDER_BY_JPQL);
		}

		String sql = query.toString();

		Query q = session.createQuery(sql);

		q.setFirstResult(0);
		q.setMaxResults(2);

		QueryPos qPos = QueryPos.getInstance(q);

		if (videoName != null) {
			qPos.add(videoName);
		}

		qPos.add(uploaderId);

		if (orderByComparator != null) {
			Object[] values = orderByComparator.getOrderByConditionValues(videoEntry);

			for (Object value : values) {
				qPos.add(value);
			}
		}

		List<VideoEntry> list = q.list();

		if (list.size() == 2) {
			return list.get(1);
		}
		else {
			return null;
		}
	}

	/**
	 * Returns all the video entries.
	 *
	 * @return the video entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<VideoEntry> findAll() throws SystemException {
		return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
	}

	/**
	 * Returns a range of all the video entries.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param start the lower bound of the range of video entries
	 * @param end the upper bound of the range of video entries (not inclusive)
	 * @return the range of video entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<VideoEntry> findAll(int start, int end)
		throws SystemException {
		return findAll(start, end, null);
	}

	/**
	 * Returns an ordered range of all the video entries.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param start the lower bound of the range of video entries
	 * @param end the upper bound of the range of video entries (not inclusive)
	 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
	 * @return the ordered range of video entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<VideoEntry> findAll(int start, int end,
		OrderByComparator orderByComparator) throws SystemException {
		FinderPath finderPath = null;
		Object[] finderArgs = new Object[] { start, end, orderByComparator };

		if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
				(orderByComparator == null)) {
			finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
			finderArgs = FINDER_ARGS_EMPTY;
		}
		else {
			finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
			finderArgs = new Object[] { start, end, orderByComparator };
		}

		List<VideoEntry> list = (List<VideoEntry>)FinderCacheUtil.getResult(finderPath,
				finderArgs, this);

		if (list == null) {
			StringBundler query = null;
			String sql = null;

			if (orderByComparator != null) {
				query = new StringBundler(2 +
						(orderByComparator.getOrderByFields().length * 3));

				query.append(_SQL_SELECT_VIDEOENTRY);

				appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
					orderByComparator);

				sql = query.toString();
			}
			else {
				sql = _SQL_SELECT_VIDEOENTRY.concat(VideoEntryModelImpl.ORDER_BY_JPQL);
			}

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				if (orderByComparator == null) {
					list = (List<VideoEntry>)QueryUtil.list(q, getDialect(),
							start, end, false);

					Collections.sort(list);
				}
				else {
					list = (List<VideoEntry>)QueryUtil.list(q, getDialect(),
							start, end);
				}
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(finderPath, finderArgs);
				}
				else {
					cacheResult(list);

					FinderCacheUtil.putResult(finderPath, finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	/**
	 * Removes all the video entries where videoName = &#63; and uploaderId = &#63; and folderId = &#63; from the database.
	 *
	 * @param videoName the video name
	 * @param uploaderId the uploader ID
	 * @param folderId the folder ID
	 * @throws SystemException if a system exception occurred
	 */
	public void removeByName_UploaderId_FolderId(String videoName,
		long uploaderId, long folderId) throws SystemException {
		for (VideoEntry videoEntry : findByName_UploaderId_FolderId(videoName,
				uploaderId, folderId)) {
			remove(videoEntry);
		}
	}

	/**
	 * Removes all the video entries where videoName = &#63; and uploaderId = &#63; from the database.
	 *
	 * @param videoName the video name
	 * @param uploaderId the uploader ID
	 * @throws SystemException if a system exception occurred
	 */
	public void removeByName_UploaderId(String videoName, long uploaderId)
		throws SystemException {
		for (VideoEntry videoEntry : findByName_UploaderId(videoName, uploaderId)) {
			remove(videoEntry);
		}
	}

	/**
	 * Removes all the video entries from the database.
	 *
	 * @throws SystemException if a system exception occurred
	 */
	public void removeAll() throws SystemException {
		for (VideoEntry videoEntry : findAll()) {
			remove(videoEntry);
		}
	}

	/**
	 * Returns the number of video entries where videoName = &#63; and uploaderId = &#63; and folderId = &#63;.
	 *
	 * @param videoName the video name
	 * @param uploaderId the uploader ID
	 * @param folderId the folder ID
	 * @return the number of matching video entries
	 * @throws SystemException if a system exception occurred
	 */
	public int countByName_UploaderId_FolderId(String videoName,
		long uploaderId, long folderId) throws SystemException {
		Object[] finderArgs = new Object[] { videoName, uploaderId, folderId };

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_NAME_UPLOADERID_FOLDERID,
				finderArgs, this);

		if (count == null) {
			StringBundler query = new StringBundler(4);

			query.append(_SQL_COUNT_VIDEOENTRY_WHERE);

			if (videoName == null) {
				query.append(_FINDER_COLUMN_NAME_UPLOADERID_FOLDERID_VIDEONAME_1);
			}
			else {
				if (videoName.equals(StringPool.BLANK)) {
					query.append(_FINDER_COLUMN_NAME_UPLOADERID_FOLDERID_VIDEONAME_3);
				}
				else {
					query.append(_FINDER_COLUMN_NAME_UPLOADERID_FOLDERID_VIDEONAME_2);
				}
			}

			query.append(_FINDER_COLUMN_NAME_UPLOADERID_FOLDERID_UPLOADERID_2);

			query.append(_FINDER_COLUMN_NAME_UPLOADERID_FOLDERID_FOLDERID_2);

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				if (videoName != null) {
					qPos.add(videoName);
				}

				qPos.add(uploaderId);

				qPos.add(folderId);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NAME_UPLOADERID_FOLDERID,
					finderArgs, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Returns the number of video entries where videoName = &#63; and uploaderId = &#63;.
	 *
	 * @param videoName the video name
	 * @param uploaderId the uploader ID
	 * @return the number of matching video entries
	 * @throws SystemException if a system exception occurred
	 */
	public int countByName_UploaderId(String videoName, long uploaderId)
		throws SystemException {
		Object[] finderArgs = new Object[] { videoName, uploaderId };

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_NAME_UPLOADERID,
				finderArgs, this);

		if (count == null) {
			StringBundler query = new StringBundler(3);

			query.append(_SQL_COUNT_VIDEOENTRY_WHERE);

			if (videoName == null) {
				query.append(_FINDER_COLUMN_NAME_UPLOADERID_VIDEONAME_1);
			}
			else {
				if (videoName.equals(StringPool.BLANK)) {
					query.append(_FINDER_COLUMN_NAME_UPLOADERID_VIDEONAME_3);
				}
				else {
					query.append(_FINDER_COLUMN_NAME_UPLOADERID_VIDEONAME_2);
				}
			}

			query.append(_FINDER_COLUMN_NAME_UPLOADERID_UPLOADERID_2);

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				if (videoName != null) {
					qPos.add(videoName);
				}

				qPos.add(uploaderId);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NAME_UPLOADERID,
					finderArgs, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Returns the number of video entries.
	 *
	 * @return the number of video entries
	 * @throws SystemException if a system exception occurred
	 */
	public int countAll() throws SystemException {
		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
				FINDER_ARGS_EMPTY, this);

		if (count == null) {
			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(_SQL_COUNT_VIDEOENTRY);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
					FINDER_ARGS_EMPTY, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Returns all the user entries associated with the video entry.
	 *
	 * @param pk the primary key of the video entry
	 * @return the user entries associated with the video entry
	 * @throws SystemException if a system exception occurred
	 */
	public List<vn.com.fis.portal.model.UserEntry> getUserEntries(long pk)
		throws SystemException {
		return getUserEntries(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
	}

	/**
	 * Returns a range of all the user entries associated with the video entry.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param pk the primary key of the video entry
	 * @param start the lower bound of the range of video entries
	 * @param end the upper bound of the range of video entries (not inclusive)
	 * @return the range of user entries associated with the video entry
	 * @throws SystemException if a system exception occurred
	 */
	public List<vn.com.fis.portal.model.UserEntry> getUserEntries(long pk,
		int start, int end) throws SystemException {
		return getUserEntries(pk, start, end, null);
	}

	public static final FinderPath FINDER_PATH_GET_USERENTRIES = new FinderPath(vn.com.fis.portal.model.impl.UserEntryModelImpl.ENTITY_CACHE_ENABLED,
			VideoEntryModelImpl.FINDER_CACHE_ENABLED_TBL_VIDEO_USER,
			vn.com.fis.portal.model.impl.UserEntryImpl.class,
			VideoEntryModelImpl.MAPPING_TABLE_TBL_VIDEO_USER_NAME,
			"getUserEntries",
			new String[] {
				Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
				"com.liferay.portal.kernel.util.OrderByComparator"
			});

	/**
	 * Returns an ordered range of all the user entries associated with the video entry.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param pk the primary key of the video entry
	 * @param start the lower bound of the range of video entries
	 * @param end the upper bound of the range of video entries (not inclusive)
	 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
	 * @return the ordered range of user entries associated with the video entry
	 * @throws SystemException if a system exception occurred
	 */
	public List<vn.com.fis.portal.model.UserEntry> getUserEntries(long pk,
		int start, int end, OrderByComparator orderByComparator)
		throws SystemException {
		Object[] finderArgs = new Object[] { pk, start, end, orderByComparator };

		List<vn.com.fis.portal.model.UserEntry> list = (List<vn.com.fis.portal.model.UserEntry>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERENTRIES,
				finderArgs, this);

		if (list == null) {
			Session session = null;

			try {
				session = openSession();

				String sql = null;

				if (orderByComparator != null) {
					sql = _SQL_GETUSERENTRIES.concat(ORDER_BY_CLAUSE)
											 .concat(orderByComparator.getOrderBy());
				}
				else {
					sql = _SQL_GETUSERENTRIES.concat(vn.com.fis.portal.model.impl.UserEntryModelImpl.ORDER_BY_SQL);
				}

				SQLQuery q = session.createSQLQuery(sql);

				q.addEntity("tbl_user",
					vn.com.fis.portal.model.impl.UserEntryImpl.class);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(pk);

				list = (List<vn.com.fis.portal.model.UserEntry>)QueryUtil.list(q,
						getDialect(), start, end);
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(FINDER_PATH_GET_USERENTRIES,
						finderArgs);
				}
				else {
					userEntryPersistence.cacheResult(list);

					FinderCacheUtil.putResult(FINDER_PATH_GET_USERENTRIES,
						finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	public static final FinderPath FINDER_PATH_GET_USERENTRIES_SIZE = new FinderPath(vn.com.fis.portal.model.impl.UserEntryModelImpl.ENTITY_CACHE_ENABLED,
			VideoEntryModelImpl.FINDER_CACHE_ENABLED_TBL_VIDEO_USER,
			Long.class, VideoEntryModelImpl.MAPPING_TABLE_TBL_VIDEO_USER_NAME,
			"getUserEntriesSize", new String[] { Long.class.getName() });

	/**
	 * Returns the number of user entries associated with the video entry.
	 *
	 * @param pk the primary key of the video entry
	 * @return the number of user entries associated with the video entry
	 * @throws SystemException if a system exception occurred
	 */
	public int getUserEntriesSize(long pk) throws SystemException {
		Object[] finderArgs = new Object[] { pk };

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERENTRIES_SIZE,
				finderArgs, this);

		if (count == null) {
			Session session = null;

			try {
				session = openSession();

				SQLQuery q = session.createSQLQuery(_SQL_GETUSERENTRIESSIZE);

				q.addScalar(COUNT_COLUMN_NAME,
					com.liferay.portal.kernel.dao.orm.Type.LONG);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(pk);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_GET_USERENTRIES_SIZE,
					finderArgs, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	public static final FinderPath FINDER_PATH_CONTAINS_USERENTRY = new FinderPath(vn.com.fis.portal.model.impl.UserEntryModelImpl.ENTITY_CACHE_ENABLED,
			VideoEntryModelImpl.FINDER_CACHE_ENABLED_TBL_VIDEO_USER,
			Boolean.class,
			VideoEntryModelImpl.MAPPING_TABLE_TBL_VIDEO_USER_NAME,
			"containsUserEntry",
			new String[] { Long.class.getName(), Long.class.getName() });

	/**
	 * Returns <code>true</code> if the user entry is associated with the video entry.
	 *
	 * @param pk the primary key of the video entry
	 * @param userEntryPK the primary key of the user entry
	 * @return <code>true</code> if the user entry is associated with the video entry; <code>false</code> otherwise
	 * @throws SystemException if a system exception occurred
	 */
	public boolean containsUserEntry(long pk, long userEntryPK)
		throws SystemException {
		Object[] finderArgs = new Object[] { pk, userEntryPK };

		Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USERENTRY,
				finderArgs, this);

		if (value == null) {
			try {
				value = Boolean.valueOf(containsUserEntry.contains(pk,
							userEntryPK));
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (value == null) {
					value = Boolean.FALSE;
				}

				FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USERENTRY,
					finderArgs, value);
			}
		}

		return value.booleanValue();
	}

	/**
	 * Returns <code>true</code> if the video entry has any user entries associated with it.
	 *
	 * @param pk the primary key of the video entry to check for associations with user entries
	 * @return <code>true</code> if the video entry has any user entries associated with it; <code>false</code> otherwise
	 * @throws SystemException if a system exception occurred
	 */
	public boolean containsUserEntries(long pk) throws SystemException {
		if (getUserEntriesSize(pk) > 0) {
			return true;
		}
		else {
			return false;
		}
	}

	/**
	 * Adds an association between the video entry and the user entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
	 *
	 * @param pk the primary key of the video entry
	 * @param userEntryPK the primary key of the user entry
	 * @throws SystemException if a system exception occurred
	 */
	public void addUserEntry(long pk, long userEntryPK)
		throws SystemException {
		try {
			addUserEntry.add(pk, userEntryPK);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(VideoEntryModelImpl.MAPPING_TABLE_TBL_VIDEO_USER_NAME);
		}
	}

	/**
	 * Adds an association between the video entry and the user entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
	 *
	 * @param pk the primary key of the video entry
	 * @param userEntry the user entry
	 * @throws SystemException if a system exception occurred
	 */
	public void addUserEntry(long pk,
		vn.com.fis.portal.model.UserEntry userEntry) throws SystemException {
		try {
			addUserEntry.add(pk, userEntry.getPrimaryKey());
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(VideoEntryModelImpl.MAPPING_TABLE_TBL_VIDEO_USER_NAME);
		}
	}

	/**
	 * Adds an association between the video entry and the user entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
	 *
	 * @param pk the primary key of the video entry
	 * @param userEntryPKs the primary keys of the user entries
	 * @throws SystemException if a system exception occurred
	 */
	public void addUserEntries(long pk, long[] userEntryPKs)
		throws SystemException {
		try {
			for (long userEntryPK : userEntryPKs) {
				addUserEntry.add(pk, userEntryPK);
			}
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(VideoEntryModelImpl.MAPPING_TABLE_TBL_VIDEO_USER_NAME);
		}
	}

	/**
	 * Adds an association between the video entry and the user entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
	 *
	 * @param pk the primary key of the video entry
	 * @param userEntries the user entries
	 * @throws SystemException if a system exception occurred
	 */
	public void addUserEntries(long pk,
		List<vn.com.fis.portal.model.UserEntry> userEntries)
		throws SystemException {
		try {
			for (vn.com.fis.portal.model.UserEntry userEntry : userEntries) {
				addUserEntry.add(pk, userEntry.getPrimaryKey());
			}
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(VideoEntryModelImpl.MAPPING_TABLE_TBL_VIDEO_USER_NAME);
		}
	}

	/**
	 * Clears all associations between the video entry and its user entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
	 *
	 * @param pk the primary key of the video entry to clear the associated user entries from
	 * @throws SystemException if a system exception occurred
	 */
	public void clearUserEntries(long pk) throws SystemException {
		try {
			clearUserEntries.clear(pk);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(VideoEntryModelImpl.MAPPING_TABLE_TBL_VIDEO_USER_NAME);
		}
	}

	/**
	 * Removes the association between the video entry and the user entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
	 *
	 * @param pk the primary key of the video entry
	 * @param userEntryPK the primary key of the user entry
	 * @throws SystemException if a system exception occurred
	 */
	public void removeUserEntry(long pk, long userEntryPK)
		throws SystemException {
		try {
			removeUserEntry.remove(pk, userEntryPK);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(VideoEntryModelImpl.MAPPING_TABLE_TBL_VIDEO_USER_NAME);
		}
	}

	/**
	 * Removes the association between the video entry and the user entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
	 *
	 * @param pk the primary key of the video entry
	 * @param userEntry the user entry
	 * @throws SystemException if a system exception occurred
	 */
	public void removeUserEntry(long pk,
		vn.com.fis.portal.model.UserEntry userEntry) throws SystemException {
		try {
			removeUserEntry.remove(pk, userEntry.getPrimaryKey());
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(VideoEntryModelImpl.MAPPING_TABLE_TBL_VIDEO_USER_NAME);
		}
	}

	/**
	 * Removes the association between the video entry and the user entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
	 *
	 * @param pk the primary key of the video entry
	 * @param userEntryPKs the primary keys of the user entries
	 * @throws SystemException if a system exception occurred
	 */
	public void removeUserEntries(long pk, long[] userEntryPKs)
		throws SystemException {
		try {
			for (long userEntryPK : userEntryPKs) {
				removeUserEntry.remove(pk, userEntryPK);
			}
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(VideoEntryModelImpl.MAPPING_TABLE_TBL_VIDEO_USER_NAME);
		}
	}

	/**
	 * Removes the association between the video entry and the user entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
	 *
	 * @param pk the primary key of the video entry
	 * @param userEntries the user entries
	 * @throws SystemException if a system exception occurred
	 */
	public void removeUserEntries(long pk,
		List<vn.com.fis.portal.model.UserEntry> userEntries)
		throws SystemException {
		try {
			for (vn.com.fis.portal.model.UserEntry userEntry : userEntries) {
				removeUserEntry.remove(pk, userEntry.getPrimaryKey());
			}
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(VideoEntryModelImpl.MAPPING_TABLE_TBL_VIDEO_USER_NAME);
		}
	}

	/**
	 * Sets the user entries associated with the video entry, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
	 *
	 * @param pk the primary key of the video entry
	 * @param userEntryPKs the primary keys of the user entries to be associated with the video entry
	 * @throws SystemException if a system exception occurred
	 */
	public void setUserEntries(long pk, long[] userEntryPKs)
		throws SystemException {
		try {
			Set<Long> userEntryPKSet = SetUtil.fromArray(userEntryPKs);

			List<vn.com.fis.portal.model.UserEntry> userEntries = getUserEntries(pk);

			for (vn.com.fis.portal.model.UserEntry userEntry : userEntries) {
				if (!userEntryPKSet.remove(userEntry.getPrimaryKey())) {
					removeUserEntry.remove(pk, userEntry.getPrimaryKey());
				}
			}

			for (Long userEntryPK : userEntryPKSet) {
				addUserEntry.add(pk, userEntryPK);
			}
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(VideoEntryModelImpl.MAPPING_TABLE_TBL_VIDEO_USER_NAME);
		}
	}

	/**
	 * Sets the user entries associated with the video entry, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
	 *
	 * @param pk the primary key of the video entry
	 * @param userEntries the user entries to be associated with the video entry
	 * @throws SystemException if a system exception occurred
	 */
	public void setUserEntries(long pk,
		List<vn.com.fis.portal.model.UserEntry> userEntries)
		throws SystemException {
		try {
			long[] userEntryPKs = new long[userEntries.size()];

			for (int i = 0; i < userEntries.size(); i++) {
				vn.com.fis.portal.model.UserEntry userEntry = userEntries.get(i);

				userEntryPKs[i] = userEntry.getPrimaryKey();
			}

			setUserEntries(pk, userEntryPKs);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(VideoEntryModelImpl.MAPPING_TABLE_TBL_VIDEO_USER_NAME);
		}
	}

	/**
	 * Returns all the category entries associated with the video entry.
	 *
	 * @param pk the primary key of the video entry
	 * @return the category entries associated with the video entry
	 * @throws SystemException if a system exception occurred
	 */
	public List<vn.com.fis.portal.model.CategoryEntry> getCategoryEntries(
		long pk) throws SystemException {
		return getCategoryEntries(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
	}

	/**
	 * Returns a range of all the category entries associated with the video entry.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param pk the primary key of the video entry
	 * @param start the lower bound of the range of video entries
	 * @param end the upper bound of the range of video entries (not inclusive)
	 * @return the range of category entries associated with the video entry
	 * @throws SystemException if a system exception occurred
	 */
	public List<vn.com.fis.portal.model.CategoryEntry> getCategoryEntries(
		long pk, int start, int end) throws SystemException {
		return getCategoryEntries(pk, start, end, null);
	}

	public static final FinderPath FINDER_PATH_GET_CATEGORYENTRIES = new FinderPath(vn.com.fis.portal.model.impl.CategoryEntryModelImpl.ENTITY_CACHE_ENABLED,
			VideoEntryModelImpl.FINDER_CACHE_ENABLED_TBL_CATEGORY_VIDEO,
			vn.com.fis.portal.model.impl.CategoryEntryImpl.class,
			VideoEntryModelImpl.MAPPING_TABLE_TBL_CATEGORY_VIDEO_NAME,
			"getCategoryEntries",
			new String[] {
				Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
				"com.liferay.portal.kernel.util.OrderByComparator"
			});

	/**
	 * Returns an ordered range of all the category entries associated with the video entry.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param pk the primary key of the video entry
	 * @param start the lower bound of the range of video entries
	 * @param end the upper bound of the range of video entries (not inclusive)
	 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
	 * @return the ordered range of category entries associated with the video entry
	 * @throws SystemException if a system exception occurred
	 */
	public List<vn.com.fis.portal.model.CategoryEntry> getCategoryEntries(
		long pk, int start, int end, OrderByComparator orderByComparator)
		throws SystemException {
		Object[] finderArgs = new Object[] { pk, start, end, orderByComparator };

		List<vn.com.fis.portal.model.CategoryEntry> list = (List<vn.com.fis.portal.model.CategoryEntry>)FinderCacheUtil.getResult(FINDER_PATH_GET_CATEGORYENTRIES,
				finderArgs, this);

		if (list == null) {
			Session session = null;

			try {
				session = openSession();

				String sql = null;

				if (orderByComparator != null) {
					sql = _SQL_GETCATEGORYENTRIES.concat(ORDER_BY_CLAUSE)
												 .concat(orderByComparator.getOrderBy());
				}
				else {
					sql = _SQL_GETCATEGORYENTRIES.concat(vn.com.fis.portal.model.impl.CategoryEntryModelImpl.ORDER_BY_SQL);
				}

				SQLQuery q = session.createSQLQuery(sql);

				q.addEntity("tbl_category",
					vn.com.fis.portal.model.impl.CategoryEntryImpl.class);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(pk);

				list = (List<vn.com.fis.portal.model.CategoryEntry>)QueryUtil.list(q,
						getDialect(), start, end);
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(FINDER_PATH_GET_CATEGORYENTRIES,
						finderArgs);
				}
				else {
					categoryEntryPersistence.cacheResult(list);

					FinderCacheUtil.putResult(FINDER_PATH_GET_CATEGORYENTRIES,
						finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	public static final FinderPath FINDER_PATH_GET_CATEGORYENTRIES_SIZE = new FinderPath(vn.com.fis.portal.model.impl.CategoryEntryModelImpl.ENTITY_CACHE_ENABLED,
			VideoEntryModelImpl.FINDER_CACHE_ENABLED_TBL_CATEGORY_VIDEO,
			Long.class,
			VideoEntryModelImpl.MAPPING_TABLE_TBL_CATEGORY_VIDEO_NAME,
			"getCategoryEntriesSize", new String[] { Long.class.getName() });

	/**
	 * Returns the number of category entries associated with the video entry.
	 *
	 * @param pk the primary key of the video entry
	 * @return the number of category entries associated with the video entry
	 * @throws SystemException if a system exception occurred
	 */
	public int getCategoryEntriesSize(long pk) throws SystemException {
		Object[] finderArgs = new Object[] { pk };

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_CATEGORYENTRIES_SIZE,
				finderArgs, this);

		if (count == null) {
			Session session = null;

			try {
				session = openSession();

				SQLQuery q = session.createSQLQuery(_SQL_GETCATEGORYENTRIESSIZE);

				q.addScalar(COUNT_COLUMN_NAME,
					com.liferay.portal.kernel.dao.orm.Type.LONG);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(pk);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_GET_CATEGORYENTRIES_SIZE,
					finderArgs, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	public static final FinderPath FINDER_PATH_CONTAINS_CATEGORYENTRY = new FinderPath(vn.com.fis.portal.model.impl.CategoryEntryModelImpl.ENTITY_CACHE_ENABLED,
			VideoEntryModelImpl.FINDER_CACHE_ENABLED_TBL_CATEGORY_VIDEO,
			Boolean.class,
			VideoEntryModelImpl.MAPPING_TABLE_TBL_CATEGORY_VIDEO_NAME,
			"containsCategoryEntry",
			new String[] { Long.class.getName(), Long.class.getName() });

	/**
	 * Returns <code>true</code> if the category entry is associated with the video entry.
	 *
	 * @param pk the primary key of the video entry
	 * @param categoryEntryPK the primary key of the category entry
	 * @return <code>true</code> if the category entry is associated with the video entry; <code>false</code> otherwise
	 * @throws SystemException if a system exception occurred
	 */
	public boolean containsCategoryEntry(long pk, long categoryEntryPK)
		throws SystemException {
		Object[] finderArgs = new Object[] { pk, categoryEntryPK };

		Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_CATEGORYENTRY,
				finderArgs, this);

		if (value == null) {
			try {
				value = Boolean.valueOf(containsCategoryEntry.contains(pk,
							categoryEntryPK));
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (value == null) {
					value = Boolean.FALSE;
				}

				FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_CATEGORYENTRY,
					finderArgs, value);
			}
		}

		return value.booleanValue();
	}

	/**
	 * Returns <code>true</code> if the video entry has any category entries associated with it.
	 *
	 * @param pk the primary key of the video entry to check for associations with category entries
	 * @return <code>true</code> if the video entry has any category entries associated with it; <code>false</code> otherwise
	 * @throws SystemException if a system exception occurred
	 */
	public boolean containsCategoryEntries(long pk) throws SystemException {
		if (getCategoryEntriesSize(pk) > 0) {
			return true;
		}
		else {
			return false;
		}
	}

	/**
	 * Adds an association between the video entry and the category entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
	 *
	 * @param pk the primary key of the video entry
	 * @param categoryEntryPK the primary key of the category entry
	 * @throws SystemException if a system exception occurred
	 */
	public void addCategoryEntry(long pk, long categoryEntryPK)
		throws SystemException {
		try {
			addCategoryEntry.add(pk, categoryEntryPK);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(VideoEntryModelImpl.MAPPING_TABLE_TBL_CATEGORY_VIDEO_NAME);
		}
	}

	/**
	 * Adds an association between the video entry and the category entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
	 *
	 * @param pk the primary key of the video entry
	 * @param categoryEntry the category entry
	 * @throws SystemException if a system exception occurred
	 */
	public void addCategoryEntry(long pk,
		vn.com.fis.portal.model.CategoryEntry categoryEntry)
		throws SystemException {
		try {
			addCategoryEntry.add(pk, categoryEntry.getPrimaryKey());
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(VideoEntryModelImpl.MAPPING_TABLE_TBL_CATEGORY_VIDEO_NAME);
		}
	}

	/**
	 * Adds an association between the video entry and the category entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
	 *
	 * @param pk the primary key of the video entry
	 * @param categoryEntryPKs the primary keys of the category entries
	 * @throws SystemException if a system exception occurred
	 */
	public void addCategoryEntries(long pk, long[] categoryEntryPKs)
		throws SystemException {
		try {
			for (long categoryEntryPK : categoryEntryPKs) {
				addCategoryEntry.add(pk, categoryEntryPK);
			}
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(VideoEntryModelImpl.MAPPING_TABLE_TBL_CATEGORY_VIDEO_NAME);
		}
	}

	/**
	 * Adds an association between the video entry and the category entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
	 *
	 * @param pk the primary key of the video entry
	 * @param categoryEntries the category entries
	 * @throws SystemException if a system exception occurred
	 */
	public void addCategoryEntries(long pk,
		List<vn.com.fis.portal.model.CategoryEntry> categoryEntries)
		throws SystemException {
		try {
			for (vn.com.fis.portal.model.CategoryEntry categoryEntry : categoryEntries) {
				addCategoryEntry.add(pk, categoryEntry.getPrimaryKey());
			}
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(VideoEntryModelImpl.MAPPING_TABLE_TBL_CATEGORY_VIDEO_NAME);
		}
	}

	/**
	 * Clears all associations between the video entry and its category entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
	 *
	 * @param pk the primary key of the video entry to clear the associated category entries from
	 * @throws SystemException if a system exception occurred
	 */
	public void clearCategoryEntries(long pk) throws SystemException {
		try {
			clearCategoryEntries.clear(pk);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(VideoEntryModelImpl.MAPPING_TABLE_TBL_CATEGORY_VIDEO_NAME);
		}
	}

	/**
	 * Removes the association between the video entry and the category entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
	 *
	 * @param pk the primary key of the video entry
	 * @param categoryEntryPK the primary key of the category entry
	 * @throws SystemException if a system exception occurred
	 */
	public void removeCategoryEntry(long pk, long categoryEntryPK)
		throws SystemException {
		try {
			removeCategoryEntry.remove(pk, categoryEntryPK);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(VideoEntryModelImpl.MAPPING_TABLE_TBL_CATEGORY_VIDEO_NAME);
		}
	}

	/**
	 * Removes the association between the video entry and the category entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
	 *
	 * @param pk the primary key of the video entry
	 * @param categoryEntry the category entry
	 * @throws SystemException if a system exception occurred
	 */
	public void removeCategoryEntry(long pk,
		vn.com.fis.portal.model.CategoryEntry categoryEntry)
		throws SystemException {
		try {
			removeCategoryEntry.remove(pk, categoryEntry.getPrimaryKey());
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(VideoEntryModelImpl.MAPPING_TABLE_TBL_CATEGORY_VIDEO_NAME);
		}
	}

	/**
	 * Removes the association between the video entry and the category entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
	 *
	 * @param pk the primary key of the video entry
	 * @param categoryEntryPKs the primary keys of the category entries
	 * @throws SystemException if a system exception occurred
	 */
	public void removeCategoryEntries(long pk, long[] categoryEntryPKs)
		throws SystemException {
		try {
			for (long categoryEntryPK : categoryEntryPKs) {
				removeCategoryEntry.remove(pk, categoryEntryPK);
			}
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(VideoEntryModelImpl.MAPPING_TABLE_TBL_CATEGORY_VIDEO_NAME);
		}
	}

	/**
	 * Removes the association between the video entry and the category entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
	 *
	 * @param pk the primary key of the video entry
	 * @param categoryEntries the category entries
	 * @throws SystemException if a system exception occurred
	 */
	public void removeCategoryEntries(long pk,
		List<vn.com.fis.portal.model.CategoryEntry> categoryEntries)
		throws SystemException {
		try {
			for (vn.com.fis.portal.model.CategoryEntry categoryEntry : categoryEntries) {
				removeCategoryEntry.remove(pk, categoryEntry.getPrimaryKey());
			}
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(VideoEntryModelImpl.MAPPING_TABLE_TBL_CATEGORY_VIDEO_NAME);
		}
	}

	/**
	 * Sets the category entries associated with the video entry, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
	 *
	 * @param pk the primary key of the video entry
	 * @param categoryEntryPKs the primary keys of the category entries to be associated with the video entry
	 * @throws SystemException if a system exception occurred
	 */
	public void setCategoryEntries(long pk, long[] categoryEntryPKs)
		throws SystemException {
		try {
			Set<Long> categoryEntryPKSet = SetUtil.fromArray(categoryEntryPKs);

			List<vn.com.fis.portal.model.CategoryEntry> categoryEntries = getCategoryEntries(pk);

			for (vn.com.fis.portal.model.CategoryEntry categoryEntry : categoryEntries) {
				if (!categoryEntryPKSet.remove(categoryEntry.getPrimaryKey())) {
					removeCategoryEntry.remove(pk, categoryEntry.getPrimaryKey());
				}
			}

			for (Long categoryEntryPK : categoryEntryPKSet) {
				addCategoryEntry.add(pk, categoryEntryPK);
			}
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(VideoEntryModelImpl.MAPPING_TABLE_TBL_CATEGORY_VIDEO_NAME);
		}
	}

	/**
	 * Sets the category entries associated with the video entry, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
	 *
	 * @param pk the primary key of the video entry
	 * @param categoryEntries the category entries to be associated with the video entry
	 * @throws SystemException if a system exception occurred
	 */
	public void setCategoryEntries(long pk,
		List<vn.com.fis.portal.model.CategoryEntry> categoryEntries)
		throws SystemException {
		try {
			long[] categoryEntryPKs = new long[categoryEntries.size()];

			for (int i = 0; i < categoryEntries.size(); i++) {
				vn.com.fis.portal.model.CategoryEntry categoryEntry = categoryEntries.get(i);

				categoryEntryPKs[i] = categoryEntry.getPrimaryKey();
			}

			setCategoryEntries(pk, categoryEntryPKs);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(VideoEntryModelImpl.MAPPING_TABLE_TBL_CATEGORY_VIDEO_NAME);
		}
	}

	/**
	 * Initializes the video entry persistence.
	 */
	public void afterPropertiesSet() {
		String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
					com.liferay.util.service.ServiceProps.get(
						"value.object.listener.vn.com.fis.portal.model.VideoEntry")));

		if (listenerClassNames.length > 0) {
			try {
				List<ModelListener<VideoEntry>> listenersList = new ArrayList<ModelListener<VideoEntry>>();

				for (String listenerClassName : listenerClassNames) {
					listenersList.add((ModelListener<VideoEntry>)InstanceFactory.newInstance(
							listenerClassName));
				}

				listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
			}
			catch (Exception e) {
				_log.error(e);
			}
		}

		containsUserEntry = new ContainsUserEntry();

		addUserEntry = new AddUserEntry();
		clearUserEntries = new ClearUserEntries();
		removeUserEntry = new RemoveUserEntry();

		containsCategoryEntry = new ContainsCategoryEntry();

		addCategoryEntry = new AddCategoryEntry();
		clearCategoryEntries = new ClearCategoryEntries();
		removeCategoryEntry = new RemoveCategoryEntry();
	}

	public void destroy() {
		EntityCacheUtil.removeCache(VideoEntryImpl.class.getName());
		FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
		FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
	}

	@BeanReference(type = CategoryEntryPersistence.class)
	protected CategoryEntryPersistence categoryEntryPersistence;
	@BeanReference(type = CategoryVideoEntryPersistence.class)
	protected CategoryVideoEntryPersistence categoryVideoEntryPersistence;
	@BeanReference(type = UserEntryPersistence.class)
	protected UserEntryPersistence userEntryPersistence;
	@BeanReference(type = VideoEntryPersistence.class)
	protected VideoEntryPersistence videoEntryPersistence;
	@BeanReference(type = VideoUserEntryPersistence.class)
	protected VideoUserEntryPersistence videoUserEntryPersistence;
	@BeanReference(type = ResourcePersistence.class)
	protected ResourcePersistence resourcePersistence;
	@BeanReference(type = UserPersistence.class)
	protected UserPersistence userPersistence;
	protected ContainsUserEntry containsUserEntry;
	protected AddUserEntry addUserEntry;
	protected ClearUserEntries clearUserEntries;
	protected RemoveUserEntry removeUserEntry;
	protected ContainsCategoryEntry containsCategoryEntry;
	protected AddCategoryEntry addCategoryEntry;
	protected ClearCategoryEntries clearCategoryEntries;
	protected RemoveCategoryEntry removeCategoryEntry;

	protected class ContainsUserEntry {
		protected ContainsUserEntry() {
			_mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
					_SQL_CONTAINSUSERENTRY,
					new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
					RowMapper.COUNT);
		}

		protected boolean contains(long videoId, long userId) {
			List<Integer> results = _mappingSqlQuery.execute(new Object[] {
						new Long(videoId), new Long(userId)
					});

			if (results.size() > 0) {
				Integer count = results.get(0);

				if (count.intValue() > 0) {
					return true;
				}
			}

			return false;
		}

		private MappingSqlQuery<Integer> _mappingSqlQuery;
	}

	protected class AddUserEntry {
		protected AddUserEntry() {
			_sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
					"INSERT INTO tbl_video_user (videoId, userId) VALUES (?, ?)",
					new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
		}

		protected void add(long videoId, long userId) throws SystemException {
			if (!containsUserEntry.contains(videoId, userId)) {
				ModelListener<vn.com.fis.portal.model.UserEntry>[] userEntryListeners =
					userEntryPersistence.getListeners();

				for (ModelListener<VideoEntry> listener : listeners) {
					listener.onBeforeAddAssociation(videoId,
						vn.com.fis.portal.model.UserEntry.class.getName(),
						userId);
				}

				for (ModelListener<vn.com.fis.portal.model.UserEntry> listener : userEntryListeners) {
					listener.onBeforeAddAssociation(userId,
						VideoEntry.class.getName(), videoId);
				}

				_sqlUpdate.update(new Object[] {
						new Long(videoId), new Long(userId)
					});

				for (ModelListener<VideoEntry> listener : listeners) {
					listener.onAfterAddAssociation(videoId,
						vn.com.fis.portal.model.UserEntry.class.getName(),
						userId);
				}

				for (ModelListener<vn.com.fis.portal.model.UserEntry> listener : userEntryListeners) {
					listener.onAfterAddAssociation(userId,
						VideoEntry.class.getName(), videoId);
				}
			}
		}

		private SqlUpdate _sqlUpdate;
	}

	protected class ClearUserEntries {
		protected ClearUserEntries() {
			_sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
					"DELETE FROM tbl_video_user WHERE videoId = ?",
					new int[] { java.sql.Types.BIGINT });
		}

		protected void clear(long videoId) throws SystemException {
			ModelListener<vn.com.fis.portal.model.UserEntry>[] userEntryListeners =
				userEntryPersistence.getListeners();

			List<vn.com.fis.portal.model.UserEntry> userEntries = null;

			if ((listeners.length > 0) || (userEntryListeners.length > 0)) {
				userEntries = getUserEntries(videoId);

				for (vn.com.fis.portal.model.UserEntry userEntry : userEntries) {
					for (ModelListener<VideoEntry> listener : listeners) {
						listener.onBeforeRemoveAssociation(videoId,
							vn.com.fis.portal.model.UserEntry.class.getName(),
							userEntry.getPrimaryKey());
					}

					for (ModelListener<vn.com.fis.portal.model.UserEntry> listener : userEntryListeners) {
						listener.onBeforeRemoveAssociation(userEntry.getPrimaryKey(),
							VideoEntry.class.getName(), videoId);
					}
				}
			}

			_sqlUpdate.update(new Object[] { new Long(videoId) });

			if ((listeners.length > 0) || (userEntryListeners.length > 0)) {
				for (vn.com.fis.portal.model.UserEntry userEntry : userEntries) {
					for (ModelListener<VideoEntry> listener : listeners) {
						listener.onAfterRemoveAssociation(videoId,
							vn.com.fis.portal.model.UserEntry.class.getName(),
							userEntry.getPrimaryKey());
					}

					for (ModelListener<vn.com.fis.portal.model.UserEntry> listener : userEntryListeners) {
						listener.onAfterRemoveAssociation(userEntry.getPrimaryKey(),
							VideoEntry.class.getName(), videoId);
					}
				}
			}
		}

		private SqlUpdate _sqlUpdate;
	}

	protected class RemoveUserEntry {
		protected RemoveUserEntry() {
			_sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
					"DELETE FROM tbl_video_user WHERE videoId = ? AND userId = ?",
					new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
		}

		protected void remove(long videoId, long userId)
			throws SystemException {
			if (containsUserEntry.contains(videoId, userId)) {
				ModelListener<vn.com.fis.portal.model.UserEntry>[] userEntryListeners =
					userEntryPersistence.getListeners();

				for (ModelListener<VideoEntry> listener : listeners) {
					listener.onBeforeRemoveAssociation(videoId,
						vn.com.fis.portal.model.UserEntry.class.getName(),
						userId);
				}

				for (ModelListener<vn.com.fis.portal.model.UserEntry> listener : userEntryListeners) {
					listener.onBeforeRemoveAssociation(userId,
						VideoEntry.class.getName(), videoId);
				}

				_sqlUpdate.update(new Object[] {
						new Long(videoId), new Long(userId)
					});

				for (ModelListener<VideoEntry> listener : listeners) {
					listener.onAfterRemoveAssociation(videoId,
						vn.com.fis.portal.model.UserEntry.class.getName(),
						userId);
				}

				for (ModelListener<vn.com.fis.portal.model.UserEntry> listener : userEntryListeners) {
					listener.onAfterRemoveAssociation(userId,
						VideoEntry.class.getName(), videoId);
				}
			}
		}

		private SqlUpdate _sqlUpdate;
	}

	protected class ContainsCategoryEntry {
		protected ContainsCategoryEntry() {
			_mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
					_SQL_CONTAINSCATEGORYENTRY,
					new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
					RowMapper.COUNT);
		}

		protected boolean contains(long videoId, long categoryId) {
			List<Integer> results = _mappingSqlQuery.execute(new Object[] {
						new Long(videoId), new Long(categoryId)
					});

			if (results.size() > 0) {
				Integer count = results.get(0);

				if (count.intValue() > 0) {
					return true;
				}
			}

			return false;
		}

		private MappingSqlQuery<Integer> _mappingSqlQuery;
	}

	protected class AddCategoryEntry {
		protected AddCategoryEntry() {
			_sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
					"INSERT INTO tbl_category_video (videoId, categoryId) VALUES (?, ?)",
					new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
		}

		protected void add(long videoId, long categoryId)
			throws SystemException {
			if (!containsCategoryEntry.contains(videoId, categoryId)) {
				ModelListener<vn.com.fis.portal.model.CategoryEntry>[] categoryEntryListeners =
					categoryEntryPersistence.getListeners();

				for (ModelListener<VideoEntry> listener : listeners) {
					listener.onBeforeAddAssociation(videoId,
						vn.com.fis.portal.model.CategoryEntry.class.getName(),
						categoryId);
				}

				for (ModelListener<vn.com.fis.portal.model.CategoryEntry> listener : categoryEntryListeners) {
					listener.onBeforeAddAssociation(categoryId,
						VideoEntry.class.getName(), videoId);
				}

				_sqlUpdate.update(new Object[] {
						new Long(videoId), new Long(categoryId)
					});

				for (ModelListener<VideoEntry> listener : listeners) {
					listener.onAfterAddAssociation(videoId,
						vn.com.fis.portal.model.CategoryEntry.class.getName(),
						categoryId);
				}

				for (ModelListener<vn.com.fis.portal.model.CategoryEntry> listener : categoryEntryListeners) {
					listener.onAfterAddAssociation(categoryId,
						VideoEntry.class.getName(), videoId);
				}
			}
		}

		private SqlUpdate _sqlUpdate;
	}

	protected class ClearCategoryEntries {
		protected ClearCategoryEntries() {
			_sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
					"DELETE FROM tbl_category_video WHERE videoId = ?",
					new int[] { java.sql.Types.BIGINT });
		}

		protected void clear(long videoId) throws SystemException {
			ModelListener<vn.com.fis.portal.model.CategoryEntry>[] categoryEntryListeners =
				categoryEntryPersistence.getListeners();

			List<vn.com.fis.portal.model.CategoryEntry> categoryEntries = null;

			if ((listeners.length > 0) || (categoryEntryListeners.length > 0)) {
				categoryEntries = getCategoryEntries(videoId);

				for (vn.com.fis.portal.model.CategoryEntry categoryEntry : categoryEntries) {
					for (ModelListener<VideoEntry> listener : listeners) {
						listener.onBeforeRemoveAssociation(videoId,
							vn.com.fis.portal.model.CategoryEntry.class.getName(),
							categoryEntry.getPrimaryKey());
					}

					for (ModelListener<vn.com.fis.portal.model.CategoryEntry> listener : categoryEntryListeners) {
						listener.onBeforeRemoveAssociation(categoryEntry.getPrimaryKey(),
							VideoEntry.class.getName(), videoId);
					}
				}
			}

			_sqlUpdate.update(new Object[] { new Long(videoId) });

			if ((listeners.length > 0) || (categoryEntryListeners.length > 0)) {
				for (vn.com.fis.portal.model.CategoryEntry categoryEntry : categoryEntries) {
					for (ModelListener<VideoEntry> listener : listeners) {
						listener.onAfterRemoveAssociation(videoId,
							vn.com.fis.portal.model.CategoryEntry.class.getName(),
							categoryEntry.getPrimaryKey());
					}

					for (ModelListener<vn.com.fis.portal.model.CategoryEntry> listener : categoryEntryListeners) {
						listener.onAfterRemoveAssociation(categoryEntry.getPrimaryKey(),
							VideoEntry.class.getName(), videoId);
					}
				}
			}
		}

		private SqlUpdate _sqlUpdate;
	}

	protected class RemoveCategoryEntry {
		protected RemoveCategoryEntry() {
			_sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
					"DELETE FROM tbl_category_video WHERE videoId = ? AND categoryId = ?",
					new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
		}

		protected void remove(long videoId, long categoryId)
			throws SystemException {
			if (containsCategoryEntry.contains(videoId, categoryId)) {
				ModelListener<vn.com.fis.portal.model.CategoryEntry>[] categoryEntryListeners =
					categoryEntryPersistence.getListeners();

				for (ModelListener<VideoEntry> listener : listeners) {
					listener.onBeforeRemoveAssociation(videoId,
						vn.com.fis.portal.model.CategoryEntry.class.getName(),
						categoryId);
				}

				for (ModelListener<vn.com.fis.portal.model.CategoryEntry> listener : categoryEntryListeners) {
					listener.onBeforeRemoveAssociation(categoryId,
						VideoEntry.class.getName(), videoId);
				}

				_sqlUpdate.update(new Object[] {
						new Long(videoId), new Long(categoryId)
					});

				for (ModelListener<VideoEntry> listener : listeners) {
					listener.onAfterRemoveAssociation(videoId,
						vn.com.fis.portal.model.CategoryEntry.class.getName(),
						categoryId);
				}

				for (ModelListener<vn.com.fis.portal.model.CategoryEntry> listener : categoryEntryListeners) {
					listener.onAfterRemoveAssociation(categoryId,
						VideoEntry.class.getName(), videoId);
				}
			}
		}

		private SqlUpdate _sqlUpdate;
	}

	private static final String _SQL_SELECT_VIDEOENTRY = "SELECT videoEntry FROM VideoEntry videoEntry";
	private static final String _SQL_SELECT_VIDEOENTRY_WHERE = "SELECT videoEntry FROM VideoEntry videoEntry WHERE ";
	private static final String _SQL_COUNT_VIDEOENTRY = "SELECT COUNT(videoEntry) FROM VideoEntry videoEntry";
	private static final String _SQL_COUNT_VIDEOENTRY_WHERE = "SELECT COUNT(videoEntry) FROM VideoEntry videoEntry WHERE ";
	private static final String _SQL_GETUSERENTRIES = "SELECT {tbl_user.*} FROM tbl_user INNER JOIN tbl_video_user ON (tbl_video_user.userId = tbl_user.userId) WHERE (tbl_video_user.videoId = ?)";
	private static final String _SQL_GETUSERENTRIESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM tbl_video_user WHERE videoId = ?";
	private static final String _SQL_CONTAINSUSERENTRY = "SELECT COUNT(*) AS COUNT_VALUE FROM tbl_video_user WHERE videoId = ? AND userId = ?";
	private static final String _SQL_GETCATEGORYENTRIES = "SELECT {tbl_category.*} FROM tbl_category INNER JOIN tbl_category_video ON (tbl_category_video.categoryId = tbl_category.categoryId) WHERE (tbl_category_video.videoId = ?)";
	private static final String _SQL_GETCATEGORYENTRIESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM tbl_category_video WHERE videoId = ?";
	private static final String _SQL_CONTAINSCATEGORYENTRY = "SELECT COUNT(*) AS COUNT_VALUE FROM tbl_category_video WHERE videoId = ? AND categoryId = ?";
	private static final String _FINDER_COLUMN_NAME_UPLOADERID_FOLDERID_VIDEONAME_1 =
		"videoEntry.videoName IS NULL AND ";
	private static final String _FINDER_COLUMN_NAME_UPLOADERID_FOLDERID_VIDEONAME_2 =
		"videoEntry.videoName = ? AND ";
	private static final String _FINDER_COLUMN_NAME_UPLOADERID_FOLDERID_VIDEONAME_3 =
		"(videoEntry.videoName IS NULL OR videoEntry.videoName = ?) AND ";
	private static final String _FINDER_COLUMN_NAME_UPLOADERID_FOLDERID_UPLOADERID_2 =
		"videoEntry.uploaderId = ? AND ";
	private static final String _FINDER_COLUMN_NAME_UPLOADERID_FOLDERID_FOLDERID_2 =
		"videoEntry.folderId = ?";
	private static final String _FINDER_COLUMN_NAME_UPLOADERID_VIDEONAME_1 = "videoEntry.videoName IS NULL AND ";
	private static final String _FINDER_COLUMN_NAME_UPLOADERID_VIDEONAME_2 = "videoEntry.videoName = ? AND ";
	private static final String _FINDER_COLUMN_NAME_UPLOADERID_VIDEONAME_3 = "(videoEntry.videoName IS NULL OR videoEntry.videoName = ?) AND ";
	private static final String _FINDER_COLUMN_NAME_UPLOADERID_UPLOADERID_2 = "videoEntry.uploaderId = ?";
	private static final String _ORDER_BY_ENTITY_ALIAS = "videoEntry.";
	private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No VideoEntry exists with the primary key ";
	private static final String _NO_SUCH_ENTITY_WITH_KEY = "No VideoEntry exists with the key {";
	private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = GetterUtil.getBoolean(PropsUtil.get(
				PropsKeys.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE));
	private static Log _log = LogFactoryUtil.getLog(VideoEntryPersistenceImpl.class);
	private static VideoEntry _nullVideoEntry = new VideoEntryImpl() {
			@Override
			public Object clone() {
				return this;
			}

			@Override
			public CacheModel<VideoEntry> toCacheModel() {
				return _nullVideoEntryCacheModel;
			}
		};

	private static CacheModel<VideoEntry> _nullVideoEntryCacheModel = new CacheModel<VideoEntry>() {
			public VideoEntry toEntityModel() {
				return _nullVideoEntry;
			}
		};
}